﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TTQT;

public partial class ThongBao : MasterControl//System.Web.UI.UserControl
{
    string noiDungTrangChu = "";
    string noiDungThongBao = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadTrangChu();
        }

    }
    private void loadTrangChu()
    {
        ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        ds.SelectCommand = "ThongBaoToanNganh_get";
        DataView hehe = (DataView)ds.Select(System.Web.UI.DataSourceSelectArguments.Empty);
        fck.Value= hehe.ToTable().Rows[0][0].ToString();
        if(hehe.ToTable().Rows[0][1].ToString().ToLower().Equals("true"))
            chkHienThongBao.Checked = true;
        else
        {
            chkHienThongBao.Checked = false;
        }
    }
    private void loadThongBao(string noiDung)
    {
        try
        {
            noiDungThongBao = noiDung.Substring(noiDung.IndexOf("start();") + 10);
            noiDungThongBao = noiDungThongBao.Substring(0, noiDungThongBao.IndexOf("</marquee>"));
            //kq = kq.TrimStart().TrimEnd();

        }
        catch (Exception layNoiDung)
        {


        }
    }
    private void alert(string noiDung)
    {
        Page.ClientScript.RegisterClientScriptBlock(System.Type.EmptyTypes.GetType(), "focusElement", @"<script>
             alert('" + noiDung + @"');             
          </script>");
    }
    protected void cmdUpdate_Click(object sender, EventArgs e)
    {

        ds.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
        ds.UpdateCommand = "ThongBaoToanNganh_update";
        ds.UpdateParameters.Clear();
        ds.UpdateParameters.Add(new Parameter("id"));
        ds.UpdateParameters["id"].DefaultValue = "1";

        ds.UpdateParameters.Add(new Parameter("noidungthongbao"));
        ds.UpdateParameters["noidungthongbao"].DefaultValue = fck.Value;

        ds.UpdateParameters.Add(new Parameter("brn_code"));
        ds.UpdateParameters["brn_code"].DefaultValue = "";

        int hide = 0;
        if (chkHienThongBao.Checked)
        {
            hide = 1;
        }
        else
        {
            hide = 0;
        }
        ds.UpdateParameters.Add(new Parameter("hide"));
        ds.UpdateParameters["hide"].DefaultValue = hide.ToString();
        ds.Update();
        Response.Redirect(Request.Url.ToString());

        //if(txtThongBao.Text.Trim().Length<1)
        //{
        //    alert("Noi dung thong bao khong duoc de trong");
        //    return;
        //}
        //loadTrangChu();
        //loadThongBao(noiDungTrangChu);
        //if (chkHienThongBao.Checked)
        //{
        //    noiDungTrangChu = noiDungTrangChu.Replace("none", "block");
        //}
        //else
        //{
        //    noiDungTrangChu = noiDungTrangChu.Replace("block", "none");
        //}
        //string tb = txtThongBao.Text;
        //if(txtThongBao.Text.Trim().Length>0)
        //{
        //    noiDungTrangChu = noiDungTrangChu.Replace(noiDungThongBao, txtThongBao.Text);
        //    noiDungTrangChu = Server.HtmlDecode(noiDungTrangChu);
        //}
        //// Lưu lại trang chủ
        //StreamWriter st = new StreamWriter(Server.MapPath("NoiDungThongBao.ascx"), false, System.Text.Encoding.Unicode);
        ////StreamWriter st = new StreamWriter(Server.MapPath("NoiDungThongBao.ascx"));
        //noiDungTrangChu = noiDungTrangChu.Replace("<", "\n<");
        //st.Write(noiDungTrangChu);
        //st.Close();
        //Response.Redirect(Request.Url.ToString());

    }
    protected void cmdCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(navigateUrl(0));
    }
}